package com.vr.xxaiagent.rag;

import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * LoveApp向量存储配置
 *
 * @author hzh
 * @date 2025/06/04
 */
@Configuration
@RequiredArgsConstructor
public class LoveAppVectorStoreConfig {

    private final LoveAppDocumentLoader loveAppDocumentLoader;

    @Bean
    public VectorStore loveAppVectorStore(EmbeddingModel dashscopeEmbeddingModel) {
        // 创建一个向量数据库
        SimpleVectorStore simplevectorStore = SimpleVectorStore.builder(dashscopeEmbeddingModel).build();
        // 加载文档
        List<Document> documents = loveAppDocumentLoader.loadMarkdowns();
        // 将文档添加到向量数据库中(会自动向量化)
        simplevectorStore.add(documents);
        return simplevectorStore;
    }
}
